package com.coincalf.wallet.web.agent;

import com.baomidou.mybatisplus.plugins.Page;
import com.coincalf.framework.http.Response;
import com.coincalf.framework.security.UserDetails;
import com.coincalf.wallet.entity.CoinRecharge;
import com.coincalf.wallet.service.CoinRechargeService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author qiang
 */
@RestController
@RequestMapping("/agent/coinRecharge")
@Slf4j
@Api(value = "代理商端-用户转入钱包", description = "代理商端-用户转入钱包")
public class AgentCoinRechargeController {

    @Autowired
    private CoinRechargeService coinRechargeService;

    @PreAuthorize("isAuthenticated()")
    @GetMapping("/recharge")
    @ApiOperation(value = "代理商-充值记录", httpMethod = "GET", authorizations = {@Authorization(value = "Authorization")})
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页大小", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "交易账户", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单编号", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "充值状态", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "coinId", value = "币种ID", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "上级ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "String", paramType = "query")})
    public Response recharge(@ApiIgnore Page<CoinRecharge> page, String userName, Integer orderId, Integer status, Integer coinId, Integer parentId, String createTime,
                             @ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return Response.ok(coinRechargeService.selectRecharges(page, userDetails.getId(), userName, orderId, status, coinId, parentId, createTime));
    }

    @GetMapping("rechargeTotal")
    @ApiOperation(value = "代理商-充值记录统计", httpMethod = "GET", authorizations = {@Authorization(value = "Authorization")})
    public Response rechargeTotal(@ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return coinRechargeService.selectRechargesTotal(userDetails.getId());
    }
}
